import * as crossSectionService from '../../services/design/crossSection';
import { notification } from 'antd';
export default {
    namespace: 'crossSection',
    state: {
       
    },
    reducers: {
       
    },
    effects: {
        *crossSectionTree({ payload:  params  }, { call, put }) {
            const res = yield call(crossSectionService.crossSectionTree, { ...params });
            return res&&res.data&&res.data.code=="200"?res.data.data:[]
        },
        *getTemplateList({ payload:  params  }, { call, put }) {
            const res = yield call(crossSectionService.getTemplateList, { ...params });
            return res&&res.data&&res.data.code=="200"?res.data.data:[]
        },
        *crossSectionTemplateDetail({ payload:  params  }, { call, put }) {
            const res = yield call(crossSectionService.crossSectionTemplateDetail, { ...params });
            return res&&res.data&&res.data.code=="200"?res.data.data:{}
        },
        *addCrossSectionTemplate({ payload: { values, onSuccess, onError } }, { call, put, select }) {
            const res = yield call(crossSectionService.addCrossSectionTemplate, values);
            if (res && res.data && res.data.code == "200") {
                notification.info({ message: "添加模板成功" });
                onSuccess(res);
            } else {
                onError(res && res.data ? res.data.message : '服务器连接失败');
            }
        },
        *addFiles({ payload: { values, onSuccess, onError } }, { call, put, select }) {
            const res = yield call(crossSectionService.addFiles, values);
            if (res && res.data && res.data.code == "200") {
                notification.info({ message: "添加模板成功" });
                onSuccess(res.data.data);
            } else {
                onError(res && res.data ? res.data.message : '服务器连接失败');
            }
            return res&&res.data&&res.data.code=="200"?res.data.data:null
        },
        *updateCrossSectionTemplate({ payload: { values, onSuccess, onError } }, { call, put, select }) {
            const res = yield call(crossSectionService.updateCrossSectionTemplate, values);
            if (res && res.data && res.data.code == "200") {
                notification.info({ message: "更新模板成功" });
                onSuccess(res);
            } else {
                onError(res && res.data ? res.data.message : '服务器连接失败');
            }
        },
        *deletecCrossSectionTemplate({ payload: { values, onSuccess, onError } }, { call, put, select }) {
            const res = yield call(crossSectionService.deletecCrossSectionTemplate, values);
            if (res && res.data && res.data.code == "200") {
                notification.info({ message: "删除模板成功" });
                onSuccess(res);
            } else {
                onError(res && res.data ? res.data.message : '服务器连接失败');
            }
        },
    }
}
